package com.f6.common.service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.f6.common.constants.CommonCanstants;
import com.f6.common.util.JsonUtil;
import com.f6.model.AccInfo;
import com.f6.model.CarModel;
import com.f6.model.CarTmodel;
import common.weixinutils.response.Article;

public class SearchService {
	
	public static Map keyMap = new HashMap();;

	public static CarModel getCarModelByVIN(String keyWord){
		String url = "http://api.carzone.cn/datasrv/2.0/car/vincode?";
		CarModel carModel = null;
		try {  
			String param = "param={\"businessCode\": \"1012\", \"params\": "
					+ "\""+keyWord+"\"}";
			url += param;
			System.out.println("vin的url为"+url);
        	JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
        	
        	if(jsonObject != null && !jsonObject.isNullObject()){
        		String result = null;
        		try{
        			result = jsonObject.getString("result");
        		}catch(Exception ex){
        			result = null;
        		}
        		if(result != null &&  result.equals("0000")){
        			JSONObject detailObject = jsonObject.getJSONObject("detail");
        			if(detailObject != null){
        				try{
    						carModel = new CarModel();
    						try{
								String mid = detailObject.getString("mid");
								carModel.setMid(Long.parseLong(mid));
							}catch(Exception ex){
    							//do nothing
								ex.printStackTrace();
    						}
							
							try{
								String id = detailObject.getString("id");
								carModel.setId(id);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String brandName = detailObject.getString("brandName");
								carModel.setBrandName(brandName);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String country = detailObject.getString("country");
								carModel.setCountry(country);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String manufacturerName = detailObject.getString("manufacturerName");
								carModel.setManufacturerName(manufacturerName);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String vehicleSystem = detailObject.getString("vehicleSystem");
								carModel.setVehicleSystem(vehicleSystem);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String salesVersion = detailObject.getString("salesVersion");
								carModel.setSalesVersion(salesVersion);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String vehicleCategory = detailObject.getString("vehicleCategory");
								carModel.setVehicleCategory(vehicleCategory);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String year = detailObject.getString("year");
								carModel.setYear(year);
							}catch(Exception ex){
    							//do nothing
    						}
							//上市年份
							try{
								String onMarketYear = detailObject.getString("onMarketYear");
								carModel.setOnMarketYear(onMarketYear);
							}catch(Exception ex){
    							//do nothing
    						}
							//上市月份
							try{
								String onMarketMonth = detailObject.getString("onMarketMonth");
								carModel.setOnMarketMonth(onMarketMonth);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String madeYear = detailObject.getString("madeYear");
								carModel.setMadeYear(madeYear);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String stopProductionYear = detailObject.getString("stopProductionYear");
								carModel.setStopProductionYear(stopProductionYear);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String length = detailObject.getString("length");
								carModel.setLength(Float.parseFloat(length));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String width = detailObject.getString("width");
								carModel.setWidth(Float.parseFloat(width));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String height = detailObject.getString("height");
								carModel.setHeight(Float.parseFloat(height));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String wheelbase = detailObject.getString("wheelbase");
								carModel.setWheelbase(Float.parseFloat(wheelbase));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String frontTread = detailObject.getString("frontTread");
								carModel.setFrontTread(Float.parseFloat(frontTread));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String rearTread = detailObject.getString("rearTread");
								carModel.setRearTread(Float.parseFloat(rearTread));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fuelTankCapacity = detailObject.getString("fuelTankCapacity");
								carModel.setFuelTankCapacity(Float.parseFloat(fuelTankCapacity));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String kerbMass = detailObject.getString("kerbMass");
								carModel.setKerbMass(Float.parseFloat(kerbMass));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String bodyForm = detailObject.getString("bodyForm");
								carModel.setBodyForm(bodyForm);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String doorNumber = detailObject.getString("doorNumber");
								carModel.setDoorNumber(doorNumber);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String seatNumber = detailObject.getString("seatNumber");
								carModel.setSeatNumber(Integer.parseInt(seatNumber));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String cylinderVolume = detailObject.getString("cylinderVolume");
								carModel.setCylinderVolume(Float.parseFloat(cylinderVolume));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String exhaustVolume = detailObject.getString("exhaustVolume");
								carModel.setExhaustVolume(exhaustVolume);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String engineType = detailObject.getString("engineType");
								carModel.setEngineType(engineType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String cylinderArrangement = detailObject.getString("cylinderArrangement");
								carModel.setCylinderArrangement(cylinderArrangement);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String cylindersNumber = detailObject.getString("cylindersNumber");
								carModel.setCylindersNumber(Integer.parseInt(cylindersNumber));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String engineDesc = detailObject.getString("engineDesc");
								carModel.setEngineDesc(engineDesc);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String powerSpeed = detailObject.getString("powerSpeed");
								carModel.setPowerSpeed(powerSpeed);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String torqueSpeed = detailObject.getString("torqueSpeed");
								carModel.setTorqueSpeed(torqueSpeed);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fuelType = detailObject.getString("fuelType");
								carModel.setFuelType(fuelType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fuelTag = detailObject.getString("fuelTag");
								carModel.setFuelTag(fuelTag);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String transmissionDesc = detailObject.getString("transmissionDesc");
								carModel.setTransmissionDesc(transmissionDesc);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fileNumber = detailObject.getString("fileNumber");
								carModel.setFileNumber(Integer.parseInt(fileNumber));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String driveForm = detailObject.getString("driveForm");
								carModel.setDriveForm(driveForm);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String frontSuspedSys = detailObject.getString("frontSuspedSys");
								carModel.setFrontSuspedSys(frontSuspedSys);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String rearSuspedSys = detailObject.getString("rearSuspedSys");
								carModel.setRearSuspedSys(rearSuspedSys);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String brakeType = detailObject.getString("brakeType");
								carModel.setBrakeType(brakeType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String powerSteeringType = detailObject.getString("powerSteeringType");
								carModel.setPowerSteeringType(powerSteeringType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String frontTireSpec = detailObject.getString("frontTireSpec");
								carModel.setFrontTireSpec(frontTireSpec);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String rearTireSpec = detailObject.getString("rearTireSpec");
								carModel.setRearTireSpec(rearTireSpec);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String hubSpec = detailObject.getString("hubSpec");
								carModel.setHubSpec(hubSpec);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String emissionStandars = detailObject.getString("emissionStandars");
								carModel.setEmissionStandars(emissionStandars);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String floorNo = detailObject.getString("floorNo");
								carModel.setFloorNo(floorNo);
							}catch(Exception ex){
    							//do nothing
    						}
        				}catch(Exception ex){
        					// do nothing
        					carModel = new CarModel();
        					carModel.setNote("这里出错啦");
        					ex.printStackTrace();
        				}
        				
        			}
        		}else{
        			carModel = new CarModel();
        			String note = jsonObject.getString("note");
        			carModel.setNote(note);
        		}
        		
        	}else{
        		carModel = new CarModel();
        		carModel.setNote("这里出错啦");
        	}
        	
        	
        } catch (Exception e) {  
            e.printStackTrace();  
        }
		
		return carModel;
	}
	
	public static CarModel getCarModelByMid(String mid){
		String url = "http://api.carzone.cn/datasrv/2.0/car/carModelInfoById?";
		CarModel carModel = null;
		try {  
			String param = "param={\"businessCode\":\"4011\",\"params\":{\"id\": \""+mid+"\",\"type\": \"0002\"}}";
			url += param;
			System.out.println("car mid的url为"+url);
        	JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
        	
        	if(jsonObject != null && !jsonObject.isNullObject()){
        		String result = null;
        		try{
        			result = jsonObject.getString("result");
        		}catch(Exception ex){
        			result = null;
        		}
        		if(result != null &&  result.equals("0000")){
        			JSONObject detailObject = jsonObject.getJSONObject("detail");
        			if(detailObject != null){
        				try{
    						carModel = new CarModel();
    						carModel.setMid(Long.parseLong(mid));
							
							try{
								String id = detailObject.getString("id");
								carModel.setId(id);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String brandName = detailObject.getString("brandName");
								carModel.setBrandName(brandName);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String country = detailObject.getString("country");
								carModel.setCountry(country);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String manufacturerName = detailObject.getString("manufacturerName");
								carModel.setManufacturerName(manufacturerName);
							}catch(Exception ex){
    							//do nothing
    						}
							
							try{
								String vehicleSystem = detailObject.getString("vehicleSystem");
								carModel.setVehicleSystem(vehicleSystem);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String salesVersion = detailObject.getString("salesVersion");
								carModel.setSalesVersion(salesVersion);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String vehicleCategory = detailObject.getString("vehicleCategory");
								carModel.setVehicleCategory(vehicleCategory);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String year = detailObject.getString("year");
								carModel.setYear(year);
							}catch(Exception ex){
    							//do nothing
    						}
							//上市年份
							try{
								String onMarketYear = detailObject.getString("onMarketYear");
								carModel.setOnMarketYear(onMarketYear);
							}catch(Exception ex){
    							//do nothing
    						}
							//上市月份
							try{
								String onMarketMonth = detailObject.getString("onMarketMonth");
								carModel.setOnMarketMonth(onMarketMonth);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String madeYear = detailObject.getString("madeYear");
								carModel.setMadeYear(madeYear);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String stopProductionYear = detailObject.getString("stopProductionYear");
								carModel.setStopProductionYear(stopProductionYear);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String length = detailObject.getString("length");
								carModel.setLength(Float.parseFloat(length));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String width = detailObject.getString("width");
								carModel.setWidth(Float.parseFloat(width));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String height = detailObject.getString("height");
								carModel.setHeight(Float.parseFloat(height));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String wheelbase = detailObject.getString("wheelbase");
								carModel.setWheelbase(Float.parseFloat(wheelbase));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String frontTread = detailObject.getString("frontTread");
								carModel.setFrontTread(Float.parseFloat(frontTread));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String rearTread = detailObject.getString("rearTread");
								carModel.setRearTread(Float.parseFloat(rearTread));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fuelTankCapacity = detailObject.getString("fuelTankCapacity");
								carModel.setFuelTankCapacity(Float.parseFloat(fuelTankCapacity));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String kerbMass = detailObject.getString("kerbMass");
								carModel.setKerbMass(Float.parseFloat(kerbMass));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String bodyForm = detailObject.getString("bodyForm");
								carModel.setBodyForm(bodyForm);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String doorNumber = detailObject.getString("doorNumber");
								carModel.setDoorNumber(doorNumber);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String seatNumber = detailObject.getString("seatNumber");
								carModel.setSeatNumber(Integer.parseInt(seatNumber));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String cylinderVolume = detailObject.getString("cylinderVolume");
								carModel.setCylinderVolume(Float.parseFloat(cylinderVolume));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String exhaustVolume = detailObject.getString("exhaustVolume");
								carModel.setExhaustVolume(exhaustVolume);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String engineType = detailObject.getString("engineType");
								carModel.setEngineType(engineType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String cylinderArrangement = detailObject.getString("cylinderArrangement");
								carModel.setCylinderArrangement(cylinderArrangement);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String cylindersNumber = detailObject.getString("cylindersNumber");
								carModel.setCylindersNumber(Integer.parseInt(cylindersNumber));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String engineDesc = detailObject.getString("engineDesc");
								carModel.setEngineDesc(engineDesc);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String powerSpeed = detailObject.getString("powerSpeed");
								carModel.setPowerSpeed(powerSpeed);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String torqueSpeed = detailObject.getString("torqueSpeed");
								carModel.setTorqueSpeed(torqueSpeed);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fuelType = detailObject.getString("fuelType");
								carModel.setFuelType(fuelType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fuelTag = detailObject.getString("fuelTag");
								carModel.setFuelTag(fuelTag);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String transmissionDesc = detailObject.getString("transmissionDesc");
								carModel.setTransmissionDesc(transmissionDesc);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String fileNumber = detailObject.getString("fileNumber");
								carModel.setFileNumber(Integer.parseInt(fileNumber));
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String driveForm = detailObject.getString("driveForm");
								carModel.setDriveForm(driveForm);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String frontSuspedSys = detailObject.getString("frontSuspedSys");
								carModel.setFrontSuspedSys(frontSuspedSys);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String rearSuspedSys = detailObject.getString("rearSuspedSys");
								carModel.setRearSuspedSys(rearSuspedSys);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String brakeType = detailObject.getString("brakeType");
								carModel.setBrakeType(brakeType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String powerSteeringType = detailObject.getString("powerSteeringType");
								carModel.setPowerSteeringType(powerSteeringType);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String frontTireSpec = detailObject.getString("frontTireSpec");
								carModel.setFrontTireSpec(frontTireSpec);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String rearTireSpec = detailObject.getString("rearTireSpec");
								carModel.setRearTireSpec(rearTireSpec);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String hubSpec = detailObject.getString("hubSpec");
								carModel.setHubSpec(hubSpec);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String emissionStandars = detailObject.getString("emissionStandars");
								carModel.setEmissionStandars(emissionStandars);
							}catch(Exception ex){
    							//do nothing
    						}
							try{
								String floorNo = detailObject.getString("floorNo");
								carModel.setFloorNo(floorNo);
							}catch(Exception ex){
    							//do nothing
    						}
        				}catch(Exception ex){
        					// do nothing
        					carModel = new CarModel();
        					carModel.setNote("这里出错啦");
        					ex.printStackTrace();
        				}
        				
        			}
        		}else{
        			carModel = new CarModel();
        			String note = jsonObject.getString("note");
        			carModel.setNote(note);
        		}
        		
        	}else{
        		carModel = new CarModel();
        		carModel.setNote("这里出错啦");
        	}
        	
        	
        } catch (Exception e) {  
            e.printStackTrace();  
        }
		
		return carModel;
	}
	
	public static boolean isVinCode(String keyword) {
		Pattern pattern = Pattern.compile("^[\\w|[0-9]]{17}$");
		Matcher matcher = pattern.matcher(keyword);
		boolean isVinCode= matcher.matches();
		return isVinCode;
	}
	
	public static CarTmodel getCarTmodelByVin(String vin){
		String url = "http://api1.carzone.cn/datasrv/2.0/outer/acc/getTmodelInfoById?";
		CarTmodel carTmodel = null;
		String param = "param={\"businessCode\": \"5021\", \"params\": {"
				+ "\"type\":\"0002\",\"vin\":\""+vin+"\"}}";
		url += param;
		System.out.println("vin变速箱的URL为："+url);
    	JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
    	if(jsonObject != null && !jsonObject.isNullObject()){
    		String result = null;
    		try{
    			result = jsonObject.getString("result");
    		}catch(Exception ex){
    			result = null;
    		}
    		if(result != null &&  result.equals("0000")){
    			//表示成功
    			JSONObject detailObject = jsonObject.getJSONObject("detail");
    			if(detailObject != null){
    				carTmodel = new CarTmodel();
					try{
						String mid = detailObject.getString("mid");
						carTmodel.setMid(mid);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String lid = detailObject.getString("lid");
						carTmodel.setLid(lid);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String tmodel = detailObject.getString("tmodel");
						carTmodel.setTmodel(tmodel);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String oilOem = detailObject.getString("oilOem");
						carTmodel.setOilOem(oilOem);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String priceFatory = detailObject.getString("priceFatory");
						carTmodel.setPriceFatory(priceFatory);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String priceMarket = detailObject.getString("priceMarket");
						carTmodel.setPriceMarket(priceMarket);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String manualOilCap = detailObject.getString("manualOilCap");
						carTmodel.setManualOilCap(manualOilCap);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String machineOilCap = detailObject.getString("machineOilCap");
						carTmodel.setMachineOilCap(machineOilCap);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String isReplace = detailObject.getString("isReplace");
						carTmodel.setIsReplace(isReplace);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String oilPrice4s = detailObject.getString("oilPrice4s");
						carTmodel.setOilPrice4s(oilPrice4s);
					}catch(Exception ex){
						//do nothing
					}
					try{
						String packagePrice4s = detailObject.getString("packagePrice4s");
						carTmodel.setPackagePrice4s(packagePrice4s);
					}catch(Exception ex){
						//do nothing
					}
    			}
    		}
    	}
    	return carTmodel;
	}
	
	public static Map getkeysMaps() {
		URL urlfile = null;
		BufferedReader in;
		try {
			urlfile = new URL(
					"http://f6car.b0.upaiyun.com/files/keys/chexiaojian.txt");
			in = new BufferedReader(new InputStreamReader(urlfile.openStream(),
					"GBK"));
			String inputLine = in.readLine();
			String lineStr[] = null;
			while (inputLine != null) {
				lineStr = inputLine.split("-");
				if(lineStr.length == 2){
					keyMap.put(lineStr[0], lineStr[1]);
				}
				inputLine = in.readLine();
			}
			System.out.println(keyMap);
			in.close();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return keyMap;
	}
	
	public static List<AccInfo> getAccInfoByList(String keyWord, String openId,
			int type) {
		String url = "http://api.carzone.cn/datasrv/2.0/acc/search?";
		List<AccInfo> list = null;
		try {
			String param = "param={\"businessCode\": \"2018\", \"params\": "
					+ "{\"keyword\":\"" + keyWord + "\",\"type\":\"" + type
					+ "\",\"facetFields\":\"\","
					+ "\"sort\":\"\",\"pageNo\":\"1\",\"pageSize\":\"10\"}}";
			url += param;
			JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
			RandomAccessFile raf = null;
			try {
				raf = new RandomAccessFile("searchKeyResult.txt", "rw");
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			String line = openId + "			" + keyWord;
			if (jsonObject != null && !jsonObject.isNullObject()) {
				String result = null;
				try {
					result = jsonObject.getString("result");
				} catch (Exception ex) {
					result = null;
				}
				if (result != null && result.equals("0000")) {
					String totalCount = jsonObject.getString("totalCount");
					line += "					" + totalCount; // 命中率为totalCount
					// 表示成功
					JSONObject detailObject = jsonObject
							.getJSONObject("detail");
					AccInfo accInfo = null;
					list = new ArrayList<AccInfo>();
					if (detailObject != null) {
						JSONArray jsonArray_accs = null;
						try {
							jsonArray_accs = detailObject
									.getJSONArray("accInfos");
							for (int i = 0; i < jsonArray_accs.size(); i++) {
								JSONObject resultObj = jsonArray_accs
										.getJSONObject(i);
								if (resultObj != null
										&& !resultObj.isNullObject()) {
									accInfo = new AccInfo();

									try {
										String accId = resultObj
												.getString("accId");
										accInfo.setAccid(accId);
										String price = getAccPrice(accId);
										accInfo.setPrice(price);
										// 根据accid求价格
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String imageId = resultObj
												.getString("imageId");
										accInfo.setImageId(imageId);
									} catch (Exception ex) {
										// do nothing
										accInfo.setImageId("/default/800x800.png!moblist");
									}

									try {
										String supplierCode = resultObj
												.getString("supplierCode");
										accInfo.setSupplierCode(supplierCode);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String accBrandName = resultObj
												.getString("accBrandName");
										accInfo.setAccBrandName(accBrandName);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String accName = resultObj
												.getString("accName");
										accInfo.setAccName(accName);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String nickName = resultObj
												.getString("nickName");
										accInfo.setNickName(nickName);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String typeName1 = resultObj
												.getString("typeName1");
										accInfo.setTypeName1(typeName1);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String typeName2 = resultObj
												.getString("typeName2");
										accInfo.setTypeName2(typeName2);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String carModels = resultObj
												.getString("carModels");
										accInfo.setCarModels(carModels);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String amount = resultObj
												.getString("amount");
										accInfo.setAmount(amount);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String isAll = resultObj
												.getString("isAll");
										accInfo.setIsAll(isAll);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String retailPrice = resultObj
												.getString("retailPrice");
										accInfo.setRetailPrice(retailPrice);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String factoryPrice = resultObj
												.getString("factoryPrice");
										accInfo.setFactoryPrice(factoryPrice);
									} catch (Exception ex) {
										// do nothing
									}

									try {
										String minUnit = resultObj
												.getString("minUnit");
										accInfo.setMinUnit(minUnit);
									} catch (Exception ex) {
										// do nothing
									}

									if (!list.contains(accInfo)) {
										list.add(accInfo);
									}
								}
							}
						} catch (Exception ex) {
							// do nothing
						}

					}

				} else {
					line += "					0"; // 命中率为0
				}

			} else {
				line += "					0"; // 命中率为0
			}

			try {
				raf.seek(raf.length());
				raf.write((line + "\n").getBytes());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return list;
	}
	
	/**
	 * 依据配件标识获取配件价格
	 * 
	 * @param accId
	 *            配件标识
	 * @return 价格
	 */
	public static String getAccPrice(String accId) {

		// 请求参数
		StringBuffer params = new StringBuffer();
		params.append("?param=").append("{\"businessCode\":").append("\"")
				.append(CommonCanstants.PRICE_BUSINESS_CODE).append("\"")
				.append(",\"params\":").append("\"").append(accId).append("\"")
				.append("}");

		String accessUrl = getAccessUrl(CommonCanstants.ACC_PRICE,
				params.toString());
		System.out.println("配件价格url:" + accessUrl);

		try {
			JSONObject jsonObject = JsonUtil
					.resolvejsonFromUrlForParam(accessUrl);
			String result = jsonObject.getString(CommonCanstants.JSON_RESULT);
			if (CommonCanstants.SUCCESS_CODE.equals(result)) {
				JSONObject detailJson = jsonObject
						.getJSONObject(CommonCanstants.JSON_DETAIL);
				String priceGeneral = detailJson.getString("priceRetail");

				return priceGeneral;
			} else {
				System.out.println("依据配件标识获取配件价格失败,返回报文为:" + result);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}

		return CommonCanstants.EMPTY_STRING;
	}
	
	private static String getAccessUrl(String urlPath, String params) {
		String requestUrl = CommonCanstants.DATA_ACCESS_URL;
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append(requestUrl).append(urlPath).append(params);

		return stringBuffer.toString();
	}
	
	public static List<Article> getArticlesByList(List<AccInfo> list,
			String keyWord) {
		List<Article> articleList = null;
		if (list != null) {
			articleList = new ArrayList<Article>();
			Article article = null;
			String isAll = "否";
			int count = 1;
			for (AccInfo accInfo : list) {
				if (accInfo.getIsAll().equals("1")) {
					isAll = "是";
				}
				article = new Article();
				if (count == 10) {
					article.setTitle("查看更多");
					String url = "http://weixin.carzone.cn/search?mid="
							+ keyWord + "&type=0";
					article.setUrl(url);
				} else {
					article.setTitle(accInfo.getAccBrandName()
							+ accInfo.getAccName() + "/"
							+ accInfo.getSupplierCode() + "－("
							+ accInfo.getPrice() + "元)");
					article.setDescription("");
					article.setPicUrl("http://image.carzone.cn"
							+ accInfo.getImageId());
					String url = "http://api.carzone.cn/accinfo.html?accId="
							+ accInfo.getAccid();
					if (accInfo.getSupplierCode() != null) {
						String code = accInfo.getSupplierCode();
						if (accInfo.getSupplierCode().contains("*")) {
							int index = accInfo.getSupplierCode().indexOf("*");
							code = accInfo.getSupplierCode()
									.substring(0, index);
						}
						url = "http://weixin.carzone.cn/search?mid=" + code
								+ "&type=0";
					}
					article.setUrl(url);
				}
				if (!articleList.contains(article)) {
					articleList.add(article);
				}
				count++;
			}
		}
		return articleList;
	}
	
	public static void main(String[] args){
		Map map = getkeysMaps();
		String ss = "你好";
		String value = (String) map.get(ss);
		if(value != null){
			System.out.println(value);
		}else{
			System.out.println("没有找到");
		}
	}
}
